var marketId = readData(localStorage.marketId);
var mycircle = document.getElementById("maycircle");
//vue实例化对象
var brand = new Vue({
	el: "#brand",
	methods: {
		loadMore: loadMore,
		openGuan: openGuan,
		openCir: openCir,
	},
	data: {
		Circles: [], //未关注
		myCircles: [], //关注过的
	}
})

function initLoad() {
	//取得登陆后关注品牌
	if (localStorage.account) {
		var circleurl = getUrl("86myAttention"); //关注圈子
		var headerJson = getHeader();
		var cid = readData(localStorage.account);
		brand.$http({
			url: circleurl,
			method: 'post',
			headers: headerJson,
			data: "accountId=" + cid + "&marketId=" + marketId
		}).then(function(repson) {
			var data = repson.data;
			if (data.code == "0") {
				mycircle.style.display = "block";
				if (data.obj) {
					var circle = data.obj;
					brand.$set('myCircles', circle);
					brand.$set('attionhide', false);
				} else {
					brand.$set('attionhide', true);
				}

			} else {
				console.log("网络链接异常，请稍后重试" + data.code)
			}
		}, function(response) {});
	}
}
//上拉加载更多
function loadMore() {
	if (localStorage.account) {
		params1 = "indexPage=" + ipagenum + "&pageSize=" + ipagesizenum + "&marketId=" + marketId + "&accountId=" + readData(localStorage.account);
		request = {
			url: noCircleurl,
			method: 'post',
			headers: getHeader(),
			data: params1
		}
	} else {
		params1 = {
			"indexPage": ipagenum,
			"pageSize": ipagesizenum,
			"city": readData(localStorage.currentCity),
			"marketId": marketId
		}
		request = {
			url: noCircleurl,
			method: 'post',
			params: params1
		}
	}
	brand.$http(request).then(function(repson) {
		ipagenum++;
		var data = repson.data;
		//alert(JSON.stringify(data))
		if (data.obj) {
			var circle = data.obj.list;
			serverNum = data.obj.totalPage;
			for (var i = 0; i < circle.length; i++) {
				brand.Circles.push(circle[i]);
			}
		} else {
			mui.toast("暂无推荐品牌了")
		}
		bRefresh = true;
	}, function(response) {
		console.log(JSON.stringify(response));
		bRefresh = true;
	});
}

function initall() {
	ipagenum = 0;
	ipagesizenum = 10;
	params1="";
	request={};
	bRefresh = true;
	brand.Circles = [];
	initLoad();
	noCircleurl = getUrl("93recommendCircle") //未关注圈子url
	brand.loadMore();
}
initall();
//打开关注
function openGuan(uid, guropId) {
	event.stopPropagation();
	openGuanzhu({
		urls: "guanzhu.html",
		uid: uid
	})
}
//打开圈子页
function openCir(gid, cname, groupId, cId) {
	openCircle({
		urls: "circleMain.html",
		guideId: gid,
		circleName: cname,
		groupId: groupId,
		circleId: cId
	})
}
var bRefresh = true;
document.addEventListener("plusready", function() {
	mui(".mui-scroll").pullToRefresh({
		up: {
			callback: function() {
				var self = this;
				if (bRefresh) {
					bRefresh = false;
					if (ipagenum <= serverNum) {
						brand.loadMore();
					}
				}
				setTimeout(function() {
					self.endPullUpToRefresh(false);
				}, 1000);
			}
		}
	});
	mui(".mui-pull-bottom-tips")[0].style.display = "none";
})
window.addEventListener("reloads", function() {
	initall();
})